package com.eece496.Server;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eece496.Database.Course;
import com.eece496.Helpers.CourseInfo;

/**
 * Servlet implementation class ProfBackPortalServlet
 */
public class ProfBackPortalServlet extends MasterServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProfBackPortalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String firstname = request.getParameter("firstname");
		String lastname = request.getParameter("lastname");
		
		//Variable for determining if the student has an empty course list
		String isEmpty = "false";
		
		//Get course List
		ArrayList<CourseInfo> info = new ArrayList<CourseInfo>();
		Course CourseDB = new Course();
		CourseDB.Setup(connection);
		try {
			info = CourseDB.GetAllCourseInfo();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//check if the prof has an empty courselist
		if(info.size() == 0)
		{
			isEmpty.equals("true");
			System.out.println(isEmpty);
		}
		
		//Forward to JSP
		request.setAttribute("firstname", firstname);		
		request.setAttribute("lastname", lastname);	
		request.setAttribute("CourseInfo", info);		
		request.setAttribute("isEmpty", isEmpty);	
		
		request.getRequestDispatcher(
				"/Professor/Professor-Portal.jsp").forward(
						request, response);
	}

}
